﻿using RpcClient;
using RpcClient.Interface;
using RpcExtend.Collect;
using RpcExtend.Model.DB;
using RpcExtend.Service.Interface;
using RpcExtendModel.SysError;
using RpcHelper;
using RpcModel;

namespace RpcExtend.Service.Service
{
    internal class SysLogService : ISysLogService
    {
        private ISysLogCollect _SysLog;
        private IUnityCollect _Unity;
        public SysLogService(ISysLogCollect sysLog, IUnityCollect unity)
        {
            this._Unity = unity;
            this._SysLog = sysLog;
        }

        public void SaveSysLog(SysErrorLog[] logs, MsgSource source)
        {
            DateTime now = DateTime.Now;
            SystemErrorLog[] sys = logs.ConvertMap<SysErrorLog, SystemErrorLog>((a, b) =>
            {
                b.ServerId = source.ServerId;
                b.RpcMerId = source.RpcMerId;
                b.SystemType = source.SystemType;
                b.AddTime = now;
                b.Id = Tools.NewGuid();
                return b;
            });
            _SysLog.AddLog(sys);
            logs.SendErrorLog(source, _Unity);
        }
    }
}
